package cn.changeforyou.analyzer.xmlparse.mybatis.reader;

import cn.changeforyou.analyzer.combine.orm.compare.EntityAndXmlComparator.XmlCompareResultNode;
import cn.changeforyou.analyzer.xmlparse.mybatis.model.MybatisXmlLabel;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;
import org.dom4j.XPath;

public abstract class AbstractXmlLabelReaderWriter<T extends MybatisXmlLabel> {
	
	public abstract void write(String[] names, XmlCompareResultNode compareResultNode, boolean isAdd);
	
	protected abstract List<T> read(List<Node> nodes);
	
	protected abstract String getXpath();
	
	public List<T> read(Document doc) {
		XPath xPath = DocumentHelper.createXPath(getXpath());
		List<Node> nodes = xPath.selectNodes(doc);
		return read(nodes);
	}
}
